#include "Cond.hpp"
#include "Mutex.hpp"
#include "Blockqueue.hpp"
#include "Task.hpp"

void *Comsumer(void *argc)
{
    Blockqueue<task_t> *bq = static_cast<Blockqueue<task_t> *>(argc);
    while (true)
    {
        sleep(3);
        task_t t = bq->Pop();
        t();
    }
}

void *Productor(void *argc)
{
    Blockqueue<task_t> *bq = static_cast<Blockqueue<task_t> *>(argc);
    while (true)
    {
        sleep(2);
        cout << "生产一个任务" << endl;
        bq->Enqueue(Download);
    }
}

int main()
{
    Blockqueue<task_t> *bq = new Blockqueue<task_t>();
    pthread_t c[1], p[1];

    pthread_create(c, nullptr, Comsumer, bq);
    pthread_create(p, nullptr, Productor, bq);

    pthread_join(c[0], nullptr);
    pthread_join(p[0], nullptr);

    return 0;
}